package com.hdoit.jiayuntong.data;

import com.ta.util.bitmap.TABitmapCallBackHanlder;
import com.ta.util.cache.TAFileCache;
import com.ta.util.cache.TAFileCache.TACacheParams;
import com.ta.util.cache.TAFileCacheWork;

import android.content.Context;
import android.content.res.Resources;
import android.widget.ImageView;

public class LocalImageCacheWork extends TAFileCacheWork<ImageView>{
	protected Resources mResources;
	private TACacheParams mCacheParams;
	private static final String TAG = "LocalImageCacheWork";
	private Context mContext;

	public LocalImageCacheWork(Context context)
	{
		mResources = context.getResources();
		this.mContext = context;
	}

	@Override
	public void loadFormCache(Object data, ImageView responseObject)
	{
		// TODO Auto-generated method stub
		if (getCallBackHandler() == null)
		{
			TABitmapCallBackHanlder callBackHanlder = new TABitmapCallBackHanlder();
			setCallBackHandler(callBackHanlder);
		}
		if (getProcessDataHandler() == null)
		{
			LocalImageHandler localBitmapFetcher = new LocalImageHandler(
					mContext, 100);
			setProcessDataHandler(localBitmapFetcher);
		}
		super.loadFormCache(data, responseObject);
	}


	public void setBitmapCache(TACacheParams cacheParams)
	{
		mCacheParams = cacheParams;
		setFileCache(new TAFileCache(cacheParams));
	}

	@Override
	protected void initDiskCacheInternal()
	{
		// TODO Auto-generated method stub
		LocalImageHandler localBitmapFetcher = (LocalImageHandler) getProcessDataHandler();
		super.initDiskCacheInternal();
		if (localBitmapFetcher != null)
		{
			localBitmapFetcher.initDiskCacheInternal();
		}
	}

	protected void clearCacheInternal()
	{
		super.clearCacheInternal();
		LocalImageHandler localBitmapFetcher = (LocalImageHandler) getProcessDataHandler();
		if (localBitmapFetcher != null)
		{
			localBitmapFetcher.clearCacheInternal();
		}
	}

	protected void flushCacheInternal()
	{
		super.flushCacheInternal();
		LocalImageHandler localBitmapFetcher = (LocalImageHandler) getProcessDataHandler();
		if (localBitmapFetcher != null)
		{
			localBitmapFetcher.flushCacheInternal();
		}
	}

	protected void closeCacheInternal()
	{
		super.closeCacheInternal();
		LocalImageHandler localBitmapFetcher = (LocalImageHandler) getProcessDataHandler();
		if (localBitmapFetcher != null)
		{
			localBitmapFetcher.closeCacheInternal();
		}
	}
}
